/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cheapflix.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;

/**
 * Abstract DAO class that handles DataSource management tasks.
 * @author Group B
 */
public abstract class AbstractDAO
{

    private DataSource dataSource;

    public void init(DataSource dataSource)
    {
        this.dataSource = dataSource;
    }

    public DataSource getDataSource()
    {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource)
    {
        this.dataSource = dataSource;
    }

    public void close(ResultSet rs)
    {
        if (rs != null)
        {
            try
            {
                rs.close();
            }
            catch (SQLException ex)
            {
                //swallow
            }
        }
    }

    public void close(Statement stmt, ResultSet rs)
    {
        if (stmt != null)
        {
            try
            {
                stmt.close();
            }
            catch (SQLException ex)
            {
                //swallow
            }
        }
        if (rs != null)
        {
            try
            {
                rs.close();
            }
            catch (SQLException ex)
            {
                //swallow
            }
        }
    }
    public void close(Connection conn, Statement stmt, ResultSet rs)
    {
          if (conn != null)
        {
            try
            {
                conn.close();
            }
            catch (SQLException ex)
            {
                //swallow
            }
        }
        if (stmt != null)
        {
            try
            {
                stmt.close();
            }
            catch (SQLException ex)
            {
                //swallow
            }
        }
        if (rs != null)
        {
            try
            {
                rs.close();
            }
            catch (SQLException ex)
            {
                //swallow
            }
        }
    }
}
